<?php

namespace api\app\middleware;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class checktoken
{
    public function handle($request, \Closure $next)
    {

        $token = request()->header();
        if(!isset($token['token']) || empty($token['token']))
        {
            return ('缺少token');
        }
        $key = new Key(config('app.jwt_key'),'HS256');
        try {
            $res = JWT::decode($token['token'],$key);

        }catch (\Exception $exception){
            return ($exception->getMessage());
        }


        $request->hello=$res->data->id;
        return $next($request);
    }
}